<?php

class ShopController
{
    private $shopModel;
    private $autoUidModel;
    private $shopGoodsType;
    private $shopGoodsRedisKey;
    private $category;
	private $templateType;
    private $newActions;
    private $plannerType;
    function __construct()/*{{{*/
    {
        $this->shopModel         =   new ShopModel();
        $this->autoUidModel      =   new AutoUidModel();
        $this->shopGoodsType     =   array('paper' => 0, 'emotion' => 1, 'font' => 2, 'pro_paper' => 3, 'pro_emotion' => 4, 'skin' => 5, 'pro_skin' => 15,'desk'=>16,'card'=>17,'tags'=>6,'plannerPaper'=>7,'stickers'=>8, 'brushs'=>9,'templet'=>10,'frames'=>11,'plugins'=>12,'bootmgrs'=>13);
    	$this->shopGoodsRedisKey =   array('paper' => 'Shop-Paper', 'emotion' => 'Shop-Emotion', 'font' => 'Shop-Font', 'skin' => 'Shop-Skin','desk'=>'Shop-Desk','card'=>'Shop-Card', 'tags'=>'Planner-Tag', 'plannerPaper'=>'Planner-Paper', 'stickers'=>'Planner-Stickers',
                                           'brushs'=>'Planner-Brushs','templet'=>'planner-Tem','frames'=>'planner-Frame','plugins'=>'planner-Plugin','bootmgrs'=>'planner-Bootmgr'
                                        );
        $this->actions           =   array(
                                        'getPaperList','getMyPaperList','getPaperDetail','buyPaper',
                                        'getEmotionList','getMyEmotionList','getEmotionDetail','buyEmotion',
                                        'getLetterPaperList','getLetterPaperDetail','getMyLetterPaperList','buyLetterPaper',
                                        'getFontList','getFontDetail','getMyFontList','buyFont',
                                        'getSkinList','getSkinDetail','getMySkinList','buySkin',

										'getCardList','getMyCardList','buyCard','getCardDetail',

                                        'getProEmotionList','getProMyEmotionList','getProEmotionDetail','buyProEmotion',
                                        'getProPaperList','getProPaperDetail','getProMyPaperList','buyProPaper',
                                        'getProSkinList','getProSkinDetail','getProMySkinList','buyProSkin',
                                        'buyPaperForSomeOne','buyEmotionForSomeOne','parseEmotion',

                                        'getResourcesById','getInterfaceInfo','getShopDisguise', 'getShopBanner',
										'getDeskList','buyDesk','getMyDeskList',
										'getHighligherList',
        );
        $this->newActions         =   array(
	    'buy'=> array('buyPlannerTags'=>'tags','buyPlannerPapers'=>'plannerPaper','buyPlannerStickers'=>'stickers',
				'buyPlannerBrushs'			=>'brushs','buyPlannerTemplets'	     =>'templet','buyPlannerFrames'=>'frames','buyPlannerPlugins'=>'plugins'),
        'list'=> array('getPlannerTagsList'		=>'tags','getPlannerNewTagsList'=>'tags','getPlannerPapersList'		=>'plannerPaper',
				'getPlannerStickersList'	=>'stickers','getPlannerNewStickersList'=>'stickers', 'getPlannerBrushsList'	=>'brushs','getPlannerNewBrushsList'=>'brushs',
				'getPlannerTempletsList'=>'templet','getPlannerNewFramesList'=>'frames','getPlannerNewPluginsList'=>'plugins','getPlannerBootmgrsList'=>'bootmgrs'),
        'mylist'=> array('getMyPlannerTagsList'	=>'tags','getMyPlannerPapersList'	=>'plannerPaper','getMyPlannerStickersList'	=>'stickers',
				'getMyPlannerBrushsList'	=>'brushs','getMyPlannerTempletsList'=>'templet','getMyPlannerFramesList'=>'frames','getMyPlannerPluginsList'=>'plugins')
        );
		$this->plannerClassInterface = array('getPlannerNewStickersList','getPlannerNewTagsList','getPlannerNewBrushsList','getPlannerNewFramesList','getPlannerNewPluginsList');
        $this->plannerType		  =   array(6=>'tags',7=>'papers',8=>'stickers',9=>'brushs',10=>'templets',11=>'frames',12=>'plugins',13=>'bootmgrs');
        $this->plannerCategorykey =   array( 6 => 'tag_category', 8 => 'sticker_category', 9 => 'brush_category', 11 => 'frame_category', 12=>'plugin_category', 13=>'bootmgr_category');
		$this->templateType = array('all'=>0, 'record' => 1, 'picture'=> 2);
    }
    
    public function callApi($param)/*{{{*/
    {
        $ac = $param['action'];
        # check $do 
        $doCheck    =   $this->checkAction($ac);
        if (!empty(AC::$errorNo))
        {
            return  $doCheck;
        }
        $result = $this->getInterfaceInfo($param);
      
        if($result !== 'nothing'){        
       		return $result;
        }
     
        return $this->$ac($param);
    }

	/**
	 * 获取手账资源分类
	 * @param $type
	 */
	public function getPlannerCategories($type){
		$list   =  $this->shopModel->getPlannerCategories($type);
		if (empty($list)){
			return  array();
		}

		$result = array();
		foreach ($list as $val){
			$catInfo    =    $this->shopModel->getPlannerCategoryInfo($val['cid'], $type, $this->plannerCategorykey[$type]);
			if (empty($catInfo)){
				continue;
			}
			$result[$val['cid']] = $catInfo['name'];
		}

		return $result;
	}

    /**
     * 获取资源包
     * @param unknown $param
     * @return boolean
     */
    public function getResourcesById($param){
    	if(empty($param['id']) || DOP::request('do')!='guest' || empty($param['type'])){
    		return false;
    	}

    	$id 		= $param['id'];
    	$type		= strval($param['type']);//标签tags 背景papers 贴纸stickers 花边笔brushs 相框frames

    	if($type == 'papers'){
    		$type = 'plannerPaper';
    	}
		if($type == 'fonts'){
			$type = 'font';
		}
    	$goodsType	=    $this->shopGoodsType[$type];
    	$redisKey 	=    $this->shopGoodsRedisKey[$type];
   
    	if(empty($goodsType) || empty($redisKey) || empty($id)){
    		return false;
    	}
    	$detail = $this->shopModel->getPlannerDetailByType($id, $goodsType);
    	$url = AC::getProtocolUriByOS($detail['zip_url']);
    	if($url){
    		//header('HTTP/1.1 301 Moved Permanently');
    		header('Location:'.$url);
    		exit();
    	}
    }

    public function getDeskList($param){
		$uid      =    $param['uid'] ? intval($param['uid']) : AC::HOST_UID;
		$type     =    strval($param['type']);
		$goodsType=    $this->shopGoodsType['desk'];
		$redisKey =    $this->shopGoodsRedisKey['desk'];

		// 获取版本号
		list($platform, $version) = $this->getPlatFormAndProductVersion();

		if (intval($uid) < 1 && DOP::request('do')!='guest'){
			AC::$errorNo = 'DCP001';
			return FALSE;
		}

		// 分页参数
		list($id, $start, $length) = UK::assemblePageData($param);

		// 请求包列表
		$shopzips = $this->shopModel->getShopZipList($platform, $goodsType, $version);
		$shopzips = $this->shopModel->getPaginationDataOfShopZipList($id, $length, $shopzips);
		if (empty($shopzips)) return (Object) array();

		// 列表
		$desks = array();
		foreach ($shopzips as $value) {
			$desk = $this->shopModel->getGoodsDetailByGoodsType($value['pid'], $goodsType, $redisKey);
			if (empty($desk)) continue;
			if (($type == 'free') && $desk['price_final'] > 0) continue;

			$desk['zip_url'] = $value['zip_url'];
			$desks[] = $desk;
		}
		if (empty($desks)) return (Object) array();

		// 组装返回结构
		$result = array();
		$result['desks']  = $this->handleShopListDataByGoodsType($desks, $uid, $goodsType);
		//$result['banner'] = $this->shopModel->getSkinBannerData();
		$result['banner'] = (Object) array();
		$result['counts'] = count($result['desks']);

		return $result;
	}

	public function buyDesk($param){
		$uid      =    intval($param['uid']);
		$id       =    intval($param['id']);
		$goodsType=    $this->shopGoodsType['desk'];
		$redisKey =    $this->shopGoodsRedisKey['desk'];

		if (empty($uid) || empty($id)){
			AC::$errorNo = 'DCP001';
			return  FALSE;
		}

		// 获取详情
		$deskDetail = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
		if (empty($deskDetail)){
			AC::$errorNo = 'DCP002';
			return false;
		}

		// 已过期报错
		if ($deskDetail['expire_time'] > 0 && $deskDetail['expire_time'] < AC::SERVER_TIME) {
			AC::$errorNo = 'DCP005';
			return false;
		}

		// 是否购买过
		$deskUser = $this->shopModel->getShopUserDetailByGoodsType($uid, $id, $goodsType);
		if ($deskUser && ($deskUser['dateline'] >= AC::SERVER_TIME || $deskUser['dateline'] == 0)){
			return TRUE;
		}

		// 判断是否符合下载条件
		$downloadCheck = $this->shopModel->checkTask($uid, $deskDetail);
		if (!$downloadCheck) {
			if (AC::$errorNo) {
				UK::varDump(AC::$errorNo, __METHOD__);
			}
			return FALSE;
		}

		// 过期时间处理(包括续约之后的过期时间)
		$contractDateline = $this->shopModel->handleContractDateline($deskUser['time'], $deskUser['dateline'], $deskDetail['period']);
		$dateline = $contractDateline['dateline'];
		$contract = $contractDateline['contract'];

		// 购买
		$result = $this->userPayFor($uid, $goodsType, $id, $deskDetail['price_final'], $dateline, $contract);
		return $result;
	}

	public function getMyDeskList($param){

		$uid      =    intval($param['uid']);
		$goodsType=    $this->shopGoodsType['desk'];
		$redisKey =    $this->shopGoodsRedisKey['desk'];

		if ($uid < 1){
			AC::$errorNo = 'DCP001';
			return false;
		}

		// 获取版本号
		list($platform, $version) = $this->getPlatFormAndProductVersion();

		// 分页参数
		list($id, $start, $length) = UK::assemblePageData($param);

		// 请求数据库
		$desks = $this->shopModel->getShopListMeBuyByGoodsType($uid, $goodsType, $start, $length, $id);
		if (empty($desks)){
			return (Object) array();
		}

		$desksWithZip = array();
		foreach ($desks as $value) {
			$shopZipInfo = $this->shopModel->getShopZipInfo($value['pid'], $platform, $version);
			$valid = $this->shopModel->checkShopZipValid($version, $shopZipInfo);
			if (!$valid) continue;

			$value['zip_url'] = $shopZipInfo['zip_url'];
			$desksWithZip[] = $value;
		}
		if (empty($desksWithZip)) return (Object) array();

		// 组装返回结构
		$result['desks']  = $this->handleShopListDataMeBuyByGoodsType($desksWithZip, $uid, $goodsType, $redisKey);
		$result['counts'] = count($result['desks']);

		return $result;
	}

	public function getShopDisguise($param){
		$result = array(
			'banners'=> array(),
			'skins'=>(Object) array(),
			'papers'=>(Object) array(),
			'fonts'=>(Object) array(),
			'emotions'=>(Object) array(),
			'desks'=>(Object) array()
		);
		$result['banners'] = $this->shopModel->getShopDisguiseBannerData();

		$res = $this->shopModel->getShopDisguise();

		if($res){
			$data = unserialize($res);
			$data['banners'] = $result['banners'];
			foreach ($data['fonts']['fonts'] as &$value){
				$value['cover']   = $this->shopModel->getnewFontCover($value['cover'],'2');
				$value['cover_s'] = $this->shopModel->getnewFontCover($value['cover_s'],'2');
			}
			$skins= $this->getSkinList($param);
			$data['skins'] = $skins ? $skins : (Object) array();
			return $data;
		}

		$desks = $this->getDeskList($param);
		$result['desks'] = $desks ? $desks : (object) array();
		
		$skins= $this->getSkinList($param);
		$result['skins'] = $skins ? $skins : (Object) array();

		$papers = $this->getLetterPaperList($param);
		$result['papers'] = $papers ? $papers : (Object) array();
		
		$fonts = $this->getFontList($param);
		$result['fonts'] = $fonts ? $fonts : (Object) array();

		$emotions = $this->getEmotionList($param);
		$result['emotions'] = $emotions ? $emotions : (Object) array();

		$data = $result;

		unset($result['banners']);
		unset($result['skins']);
		$jsonData = serialize($result);
		$this->shopModel->setShopDisguise($jsonData);

		return $data;
	}

    /**
     * 
     * 商店列表
     * @param unknown $param
     * @return boolean|number
     */
    private function getPaperList($param){
        // 参数处理
        $uid     =    intval($param['uid']);
        $type    =    strval(trim($param['type']));
    
        if (empty($uid)){
            AC::$errorNo = 'DCP001';
            return false;
        }
         
        // 默认为最新信纸列表
        if (empty($type)){
            $type = 'new';
        }
        
        // 信纸从2.4.0后全部显示
        if (AC::$paperIosDiaryShowVersion){
            $type = 'all';
        }

        $id      =    0;
        $start   =    0;
        $length  =    AC::SHOP_DEFAULT_DISPLAY_LENGTH;
        isset($param['id'])       &&    $id       =   intval($param['id']);
        isset($param['start'])    &&    $start    =   intval($param['start']);
        isset($param['length'])   &&    $length   =   intval($param['length']);
        
        // 价格区间判断
        $min_price = $max_price = 0;
        isset($param['min_price'])   &&    $min_price   =   intval($param['min_price']);
        isset($param['max_price'])   &&    $max_price   =   intval($param['max_price']);
        $min_price = abs(floor($min_price));
        $max_price = abs(floor($max_price));
        
        if ($min_price > $max_price){
            $min_price = $max_price;
        }
        
        // 获取商店信纸列表
        $result = $this->shopModel->getPaperList($type, $start, $length, $id, $min_price, $max_price);
        
        $outPut = $data = array();
        foreach ($result as $value){
            // 输出格式化
            $data = $this->shopModel->paperListData($value,$uid);
            $outPut['papers'][] = $data;
        }
        $outPut['banner'] = $this->shopModel->getPaperBannerData();
        $outPut['banner'] = (Object) array();
        $outPut['counts'] = count($outPut['papers']);
         
        return $outPut;
    }
    
    /**
     * 我购买的信纸列表
     * @param unknown $param
     * @return boolean|multitype:|number
     */
    private function getMyPaperList($param){
        $uid     =    intval($param['uid']);
    
        // 参数判断
        if (empty($uid)){
            AC::$errorNo    =   'DCP001';
            return  FALSE;
        }
    
        // 非本人不能查看
        if ($uid != AC::HOST_UID){
            AC::$errorNo    =   'DCP003';
            return  FALSE;
        }
        
        $id      =    0;
        $start   =    0;
        $length  =    AC::SHOP_DEFAULT_DISPLAY_LENGTH;
        isset($param['id'])       &&    $id       =   intval($param['id']);
        isset($param['start'])    &&    $start    =   intval($param['start']);
        isset($param['length'])   &&    $length   =   intval($param['length']);
         
        $pids = $this->shopModel->getMyPaperList($uid, $start, $length, $id);
        if (empty($pids)) {
            return (Object) array();
        }
    
        $outPut = $data = array();
        foreach ($pids as $pid){
            $paperDetail = $this->shopModel->getPaperDetail($pid['pid']);
            if (empty($paperDetail)){
                continue;
            }
            $data = $this->shopModel->paperDetailToListData($paperDetail,$uid);
            $outPut['papers'][] = $data;
        }
        $outPut['counts'] = count($outPut['papers']);
        return $outPut;
    }
    
    /**
     * 信纸详情
     * @param unknown $param
     * @return boolean|multitype:|Ambigous <boolean, multitype:string mixed , string, multitype:>
     */
    private function getPaperDetail($param){
        // 参数处理
        $uid     =    intval($param['uid']);
        $pid     =    intval($param['pid']);
         
        if (empty($pid) || empty($uid)){
            AC::$errorNo    =   'DCP001';
            return  FALSE;
        }
         
        // 获取信纸详情
        $result = $this->shopModel->getPaperDetail($pid);
        if (empty($result)){
            AC::$errorNo = 'DCP002';
            return false;
        }
        return $result;
    }
    
    /**
     * 购买信纸
     * @param unknown $param
     * @return boolean
     */
    private function buyPaper($param){
        // 参数处理
        $uid     =    intval($param['uid']);
        $pid     =    intval($param['pid']);
    
        if (empty($uid) || empty($pid)){
            AC::$errorNo = 'DCP001';
            return  FALSE;
        }
    
        $paperDetail = $this->shopModel->getPaperDetail($pid);
        if (empty($paperDetail)){
            AC::$errorNo = 'DCP002';
            return false;
        }

        $paperUser = $this->shopModel->getPaperUser($uid, $pid);
        if ($paperUser){
            return true;
        }

        // 判断是否符合下载条件
        $downloadCheck = $this->shopModel->checkTask($uid, $paperDetail);
        if (!$downloadCheck) {
            if (AC::$errorNo) {
                UK::varDump(AC::$errorNo, __METHOD__);
            }
            return FALSE;
        }
    
        // 购买
        $result = $this->userPayFor($uid, $this->shopGoodsType['paper'], $pid, $paperDetail['price_first']);
        return $result;
    }
  
	/**
	 * 我的手账资源列表
	 * @param unknown $param
	 * @return boolean|StdClass|multitype:Ambigous NULL
	 */
     private function getMyPlannerList($param){   	
    	$uid       =    intval($param['uid']);
    	$goodsType =    $param['goods']['goodsType'];
    	$redisKey  =    $param['goods']['redisKey'];
    	if($uid<1 || !isset($goodsType) || !isset($redisKey)){
    		AC::$errorNo = 'DCP001';
    		return false;
    	}
    	// 分页参数
    	list($id, $start, $length) = UK::assemblePageData($param);
    	 
    	// 请求数据库
    	$plannerList = $this->shopModel->getShopListMeBuyByGoodsType($uid, $goodsType, $start, $length, $id);
    	if (empty($plannerList)){
    		return (Object) array();
    	}
    	 
    	// 组装返回结构
    	$result = array();
    	$result['data']  = $this->handleShopListDataMeBuyByGoodsType($plannerList, $uid, $goodsType, $redisKey);
    	$result['counts']= count($result['data']);
    	 
    	return $result;
    }
    
    /**
     * 购买资源
     * @param unknown $param
     * @return boolean
     */
    private function buyPlanner($param){
    	$uid      =    intval($param['uid']);
    	$id       =    intval($param['id']);
    	$goodsType =    $param['goods']['goodsType'];
    	$redisKey  =    $param['goods']['redisKey'];
    	
    	if(!isset($goodsType) || !isset($redisKey)){
    		AC::$errorNo = 'DCP001';
    		return false;
    	}
    	if ((empty($uid) || empty($id)) && DOP::request('do')!='guest' ){
    		AC::$errorNo = 'DCP001';
    		return  FALSE;
    	}
    	 
    	// 获取详情
    	$plannerDesc = $this->shopModel->getPlannerDetailByType($id, $goodsType);
    	if (empty($plannerDesc)){
    		AC::$errorNo = 'DCP002';
    		return false;
    	}
		$support = $this->judeVersion($plannerDesc);
		if(!$support){
			AC::$errorMsg = '该版本还不支持呐￣へ￣';
			AC::$errorNo = 'DCP006';
			return false;
		}
    	//未登录下载
    	if(DOP::request('do') == 'guest'){
    	
    		if(!empty($plannerDesc['task'])){
    			 
    			$task = json_decode($plannerDesc['task'],true);
    			if(empty($task['type'])){
    		   
    				$this->shopModel->increaseSaleAmount($id);
    		   
    				return true;
    			}else{
    		   
    				return false;
    			}
    		}else{
				$this->shopModel->increaseSaleAmount($id);
    			return true;
    		}
    	
    	}
    	
    	// 已过期报错
    	if ($plannerDesc['expire_time'] > 0 && $plannerDesc['expire_time'] < AC::SERVER_TIME) {
    		AC::$errorNo = 'DCP005';
    		return false;
    	}
    	 
    	// 是否购买过
    	$plannerUser = $this->shopModel->getShopUserDetailByGoodsType($uid, $id, $goodsType);
    	if ($plannerUser && ($plannerUser['dateline'] >= AC::SERVER_TIME || $plannerUser['dateline'] == 0)){
    		return TRUE;
    	}
    	 
    	// 判断是否符合下载条件
    	$downloadCheck = $this->shopModel->checkTask($uid, $plannerDesc);
    	if (!$downloadCheck) {
    		if (AC::$errorNo) {
    			UK::varDump(AC::$errorNo, __METHOD__);
    		}
    		return FALSE;
    	}
    	 
    	// 过期时间处理(包括续约之后的过期时间)
    	$contractDateline = $this->shopModel->handleContractDateline($plannerUser['time'], $plannerUser['dateline'], $plannerDesc['period']);
    	$dateline = $contractDateline['dateline'];
    	$contract = $contractDateline['contract'];
    	 
    	// 购买
    	$result = $this->userPayFor($uid, $goodsType, $id, $plannerDesc['price_final'], $dateline, $contract);
    	return $result;
    }

	private function judeVersion($detail){
		if(!UK::isJSON($detail['versionsupport'])){
			return true;
		}
		$support = json_decode($detail['versionsupport'], true);
		$productVersion = $this->getPlatFormAndProductVersion();
		$minSupport = $support[$productVersion[0]];
		if(!$minSupport){
			return true;
		}
		if(version_compare($productVersion[1],$minSupport,'<')){
			return false;
		}
		return true;
	}
    public function getPlannerList($param){
		$uid       =    intval($param['uid']);
    	$goodsType =    $param['goods']['goodsType'];
    	$redisKey  =    $param['goods']['redisKey'];
    	
    	// check params
    	if ($uid < 1 && DOP::request('do')!='guest'){
    		AC::$errorNo = 'DCP001';
    		return false;
    	}
    	if(!isset($goodsType) || !isset($redisKey)){
    		AC::$errorNo = 'DCP001';
    		return false;
    	}
    	
    	//检查类型是否存在
    	$goods = $this->plannerType[$goodsType];
    	if(empty($goods)) return (Object) array();  	
    	
    	// 分页参数
    	list($id, $start, $length) = UK::assemblePageData($param);
    	$length   = AC::PLANNER_LENGTH;    	
    	
    	// 类型
    	$type = 'new';
    	isset($param['type']) && $type = strval($param['type']);
    	if ($type === 'all') $type = 'new';   	
    	// 请求列表
		$result[$goods]  = $this->handelPlanerListData($uid, $goodsType, $redisKey);
		
    	$result['counts'] = count($result[$goods]);

		//根据参数分类返回
		$res = $this->getPlannerListByParam($param, $result, $goods, $goodsType);
		if($res){
			return $res;
		}
		$result = $this->checkHidden($result[$goods],$goods);
    	return $result;
    }

	private function checkHidden($result,$goods){
		$res = array();	
		foreach($result as $value){
				if($value['hidden']!=1){
					array_push($res, $value);
				}
		}
		return array($goods=>$res,'counts'=>count($res));
	}
	
	private function getPlannerListByParam($param, $result, $goods, $goodsType){

		//推荐模板
		if($param['category'] == '1' && $param['action']=='getPlannerTempletsList'){
			return $this->getPlannerTempletsListByType($result[$goods],$goods);
		}

		//引导器按类别返回record picture
		if(!empty($param['kind']) && $param['action']=='getPlannerBootmgrsList'){
			return $this->getPlannerBootmgrsListByKind($result[$goods],$goods,$param['kind']);
		}
		//
		if(isset($param['kind']) && isset($param['numberOfPhoto']) && $param['action'] == 'getPlannerTempletsList'){
			return $this->getPlannerTempletsListByKind($result[$goods],$goods,$param['kind'], $param['numberOfPhoto']);
		}
	
		//分类列表
		if(in_array($param['action'],$this->plannerClassInterface)){
			return $this->getInfoBycategory($result[$goods], $goodsType);
		}
		return false;
	}

	private function getPlannerTempletsListByKind($list,$goods,$kind, $numberOfPhoto){
		$res = array();
		$res[$goods] = array();
		foreach ($list as $value){
			if($value['category'] == $numberOfPhoto && $value['kind'] == $kind){
				array_unshift($res[$goods], $value);
			}
		}
		$res['counts'] = count($res[$goods]);
		return $res;
	}
	private function getPlannerBootmgrsListByKind($list,$goods,$kind){
		$res = array();
		$res[$goods] = array();
		foreach ($list as $value){
			if($value['kind'] == $kind){
				array_unshift($res[$goods], $value);
			}
		}
		$res['counts'] = count($res[$goods]);
		return $res;
	}

    private function getPlannerTempletsListByType($list,$goods){
    	$res = array();
    	$res[$goods] = array();
    	foreach ($list as $value){
    		if($value['label'] == '1' && $value['hidden']!=1){
    			array_unshift($res[$goods], $value);
    		}
    	}
    	$res['counts'] = count($res[$goods]);
    	return $res;
    }
    
    /**
     * 手账统一接口
     * @param unknown $param
     * @return string
     */
    public function getInterfaceInfo($param){
	
    	$goodsType = $this->getPlannerType($param);
    
    	if(empty($goodsType)){
    		return 'nothing';
    	}
    	$result='';
    	$param['goods']=$goodsType; 

		$mylist = array_keys($this->newActions['mylist']);
		$list   = array_keys($this->newActions['list']);
		$buy	= array_keys($this->newActions['buy']);
    	switch($param['action']){
    		case in_array($param['action'],$mylist)://我的列表
    			$result = $this->getMyPlannerList($param);
    			break;
    		case in_array($param['action'],$buy)://购买
    			$result = $this->buyPlanner($param);
    			break;
    		case in_array($param['action'],$list)://全部列表
    			$result = $this->getPlannerList($param);
    	}
		
    	return $result;
    }


    public function getHighligherList($param){
		$result = array(
			array(
				'name'=>'荧光笔',
				'thumbnail'=>array(
					array(
						's'=>AC::getProtocolUriByOS('http://d.fenfenriji.com/diary/planner/brushs/highligher/priview/zhenghong.png'),
						'm'=>AC::getProtocolUriByOS('http://d.fenfenriji.com/diary/planner/brushs/highligher/yinguangbi/zhenghong.png'),
						'c'=>'#ff0000',
						'n'=>'正红色',
					),
					array(
						's'=>AC::getProtocolUriByOS('http://d.fenfenriji.com/diary/planner/brushs/highligher/priview/taohong.png'),
						'm'=>AC::getProtocolUriByOS('http://d.fenfenriji.com/diary/planner/brushs/highligher/yinguangbi/taohong.png'),
						'c'=>'#ff4772',
						'n'=>'桃红色',
					),
					array(
						's'=>AC::getProtocolUriByOS('http://d.fenfenriji.com/diary/planner/brushs/highligher/priview/huang.png'),
						'm'=>AC::getProtocolUriByOS('http://d.fenfenriji.com/diary/planner/brushs/highligher/yinguangbi/huang.png'),
						'c'=>'#ffe847',
						'n'=>'黄色',

					),
					array(
						's'=>AC::getProtocolUriByOS('http://d.fenfenriji.com/diary/planner/brushs/highligher/priview/lv.png'),
						'm'=>AC::getProtocolUriByOS('http://d.fenfenriji.com/diary/planner/brushs/highligher/yinguangbi/lv.png'),
						'c'=>'#7dd082',
						'n'=>'草绿色',
					),
					array(
						's'=>AC::getProtocolUriByOS('http://d.fenfenriji.com/diary/planner/brushs/highligher/priview/lanzi.png'),
						'm'=>AC::getProtocolUriByOS('http://d.fenfenriji.com/diary/planner/brushs/highligher/yinguangbi/lanzi.png'),
						'c'=>'#77a7f1',
						'n'=>'蓝紫色',
					),
					array(
						's'=>AC::getProtocolUriByOS('http://d.fenfenriji.com/diary/planner/brushs/highligher/priview/yinguanglan.png'),
						'm'=>AC::getProtocolUriByOS('http://d.fenfenriji.com/diary/planner/brushs/highligher/yinguangbi/yinguanglan.png'),
						'c'=>'#64ffee',
						'n'=>'荧光蓝',
					)
				)
			)
		);

		$res['data'] = $result;
		$res['count'] = count($result);

		return $res;
	}

    public function getPlannerType($param){
    	$plannerType = array();
    	$action		 = $param['action'];
		$goods 		 = '';
		foreach($this->newActions as $value){
				if($value[$action]){
					$goods = $value[$action];
					break;
				}
		}
		if(!$goods){ return array();}
    	$plannerType['goodsType'] = $this->shopGoodsType[$goods];
    	$plannerType['redisKey']  = $this->shopGoodsRedisKey[$goods];

    	return $plannerType;
    }
   
    /**
     * 分类返回手账数据
     * @param unknown $result
     * @return multitype:multitype:
     */
    public function getInfoBycategory($result,$type){
    	$data = array();	
    	//分类
		$category = $this->getPlannerCategories($type);
		if($category){
			foreach($category as $cid=>$cname){
				$tmp=array('data'=>array());
				$tmp['cname'] =	$cname;
				$tmp['cid']	  = $cid;
				foreach ($result as $value){
					if(!empty($value['category']) ){
						if($value['category'] == $cid && $value['hidden']!=1){
							array_push($tmp['data'],$value);
						}
					}
				}
				if(!empty($tmp['data'])){
					array_push($data,$tmp);
				}
			}
		}
    	//推荐
    	$label = array('data'=>array());
    	$label['cname'] ='推荐';
    	$label['cid']   = '1';
    	foreach ($result as $value){
    		if($value['label'] == 1 && $value['hidden']!=1){
    			array_push($label['data'],$value);
    		}
    	}
    	
    	if(!empty($label['data'])){
    		array_unshift($data,$label);
    	}
    	return array('data'=>$data,'counts'=>count($data));
    }
    //==========================================会员卡片============================================
	public function getCardDetail($param)
	{

		$uid     =    intval($param['uid']);
		$id      =    intval($param['id']);
		$goodsType=    $this->shopGoodsType['card'];
		$redisKey =    $this->shopGoodsRedisKey['card'];

		// check params
		if ($id < 1 || $uid < 1 ){
			AC::$errorNo    =   'DCP001';
			return  false;

		}

		// 获取信纸详情
		$emotionDetail = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
		if (empty($emotionDetail)){
			return (Object) array();
		}

		// 组装返回数据
		$result = $this->shopModel->assembledShopListDataByGoodsType($uid, $emotionDetail, $goodsType);
		return $result;
	}

	public function getCardList($param){
		$uid     =    intval($param['uid']);
		$goodsType=    $this->shopGoodsType['card'];
		$redisKey =    $this->shopGoodsRedisKey['card'];

		// check params
		if (intval($uid) < 1 && DOP::request('do')!='guest'){
			AC::$errorNo = 'DCP001';
			return FALSE;
		}
		// 分页参数
		list($id, $start, $length) = UK::assemblePageData($param);

		// 类型
		$type = 'new';
		isset($param['type']) && $type = strval($param['type']);
		if ($type === 'all') $type = 'new';

		// 请求列表
		$cardList = $this->shopModel->getShopIdList($redisKey, $goodsType, $type, $id, $start, $length);
		if (empty($cardList)){
			return (Object) array();
		}

		// 组装返回结构
		$result['cards']  = $this->handleShopListData($cardList, $uid, $goodsType, $redisKey);
		$result['banner'] = (Object) array();
		$result['counts'] = count($result['cards']);

		return $result;
	}
	public function getMyCardList($param){
		$uid     =    intval($param['uid']);
		$goodsType=    $this->shopGoodsType['card'];
		$redisKey =    $this->shopGoodsRedisKey['card'];

		// check params
		if ($uid < 1){
			AC::$errorNo = 'DCP001';
			return false;
		}

		// 分页参数
		list($id, $start, $length) = UK::assemblePageData($param);

		// 请求数据库
		$myCardList = $this->shopModel->getShopListMeBuyByGoodsType($uid, $goodsType, $start, $length, $id);
		if (empty($myCardList)){
			return (Object) array();
		}

		// 组装返回结构
		$result['cards']  = $this->handleShopListDataMeBuyByGoodsType($myCardList, $uid, $goodsType, $redisKey);
		$result['counts']    = count($result['cards']);

		return $result;
	}
	public function buyCard($param){
		$uid     =    intval($param['uid']);
		$id      =    intval($param['id']);
		$goodsType=    $this->shopGoodsType['card'];
		$redisKey =    $this->shopGoodsRedisKey['card'];

		// check params
		if (empty($uid) || empty($id)){
			AC::$errorNo = 'DCP001';
			return  false;
		}
		$userInfo = $this->autoUidModel->getUserInfo($uid);
		if(empty($userInfo['is_vip'])){
			AC::$errorNo = 'AUG001';
			return false;
		}
		// 获取详情
		$emotionDetail = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
		if (empty($emotionDetail)){
			AC::$errorNo = 'DCP002';
			return false;
		}

		// 已过期报错
		if ($emotionDetail['expire_time'] > 0 && $emotionDetail['expire_time'] < AC::SERVER_TIME) {
			AC::$errorNo = 'DCP005';
			return false;
		}

		// 是否购买过
		$emotionUser = $this->shopModel->getShopUserDetailByGoodsType($uid, $id, $goodsType);
		if ($emotionUser && ($emotionUser['dateline'] >= AC::SERVER_TIME || $emotionUser['dateline'] == 0)){
			return true;
		}

		// 判断是否符合下载条件
		$downloadCheck = $this->shopModel->checkTask($uid, $emotionDetail);
		if (!$downloadCheck) {
			if (AC::$errorNo) {
				UK::varDump(AC::$errorNo, __METHOD__);
			}
			return true;
		}

		// 过期时间处理(包括续约之后的过期时间)
		$contractDateline = $this->shopModel->handleContractDateline($emotionUser['time'], $emotionUser['dateline'], $emotionDetail['period']);
		$dateline = $contractDateline['dateline'];
		$contract = $contractDateline['contract'];

		// 购买
		$result = $this->userPayFor($uid, $goodsType, $id, $emotionDetail['price_final'], $dateline, $contract);
		return $result;
	}
    // =========================================表情商店============================================
    
    /**
     * 表情商店
     * @param unknown $param
     * @return boolean|StdClass|number
     */
    private function getEmotionList($param){
        $uid     =    intval($param['uid']);
        $goodsType=    $this->shopGoodsType['emotion'];
        $redisKey =    $this->shopGoodsRedisKey['emotion'];
        
        // check params
		if (intval($uid) < 1 && DOP::request('do')!='guest'){
			AC::$errorNo = 'DCP001';
			return FALSE;
		}
        // 分页参数
        list($id, $start, $length) = UK::assemblePageData($param);
        
        // 类型
        $type = 'new';
        isset($param['type']) && $type = strval($param['type']);
        if ($type === 'all') $type = 'new';
        
        // 请求列表
        $emotionList = $this->shopModel->getShopIdList($redisKey, $goodsType, $type, $id, $start, $length);
        if (empty($emotionList)){
            return (Object) array();
        }
        
        // 组装返回结构
        $result['emotions']  = $this->handleShopListData($emotionList, $uid, $goodsType, $redisKey);
        $result['banner'] = $this->shopModel->getEmotionBannerData();
        $result['banner'] = (Object) array();
        $result['counts'] = count($result['emotions']);
        
        return $result;
    }
    
    /**
     * 获取我购买的表情列表
     * @param unknown $param
     */
    private function getMyEmotionList($param){
        $uid     =    intval($param['uid']);
        $goodsType=    $this->shopGoodsType['emotion'];
        $redisKey =    $this->shopGoodsRedisKey['emotion'];
        
        // check params
        if ($uid < 1){
            AC::$errorNo = 'DCP001';
            return false;
        }
    
        // 分页参数
        list($id, $start, $length) = UK::assemblePageData($param);
    
        // 请求数据库
        $emotionList = $this->shopModel->getShopListMeBuyByGoodsType($uid, $goodsType, $start, $length, $id);
        if (empty($emotionList)){
            return (Object) array();
        }

        // 组装返回结构
        $result['emotions']  = $this->handleShopListDataMeBuyByGoodsType($emotionList, $uid, $goodsType, $redisKey);
        $result['counts']    = count($result['emotions']);
    
        return $result;
    }
    
    /**
     * 获取表情包详情
     * @param unknown $param
     * @return boolean|StdClass|unknown
     */
    private function getEmotionDetail($param){
        $uid     =    intval($param['uid']);
        $id      =    intval($param['id']);
        $goodsType=    $this->shopGoodsType['emotion'];
        $redisKey =    $this->shopGoodsRedisKey['emotion'];

        // check params
        if ($id < 1 || $uid < 1 ){
            AC::$errorNo    =   'DCP001';
            return  FALSE;
        }
         
        // 获取信纸详情
        $emotionDetail = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
        if (empty($emotionDetail)){
            return (Object) array();
        }
        
        // 组装返回数据
        $result = $this->shopModel->assembledShopDetailDataByGoodsType($uid, $emotionDetail, $goodsType);
        return $result;
    }
    
    /**
     * 表情包购买
     * @param unknown $param
     * @return boolean
     */
    private function buyEmotion($param){
        $uid     =    intval($param['uid']);
        $id      =    intval($param['id']);
        $goodsType=    $this->shopGoodsType['emotion'];
        $redisKey =    $this->shopGoodsRedisKey['emotion'];
        
        // check params
        if (empty($uid) || empty($id)){
            AC::$errorNo = 'DCP001';
            return  FALSE;
        }
        
        // 获取详情
        $emotionDetail = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
        if (empty($emotionDetail)){
            AC::$errorNo = 'DCP002';
            return false;
        }
        
        // 已过期报错
        if ($emotionDetail['expire_time'] > 0 && $emotionDetail['expire_time'] < AC::SERVER_TIME) {
            AC::$errorNo = 'DCP005';
            return false;
        }
        
        // 是否购买过
        $emotionUser = $this->shopModel->getShopUserDetailByGoodsType($uid, $id, $goodsType);
        if ($emotionUser && ($emotionUser['dateline'] >= AC::SERVER_TIME || $emotionUser['dateline'] == 0)){
            return TRUE;
        }
        
        // 判断是否符合下载条件
        $downloadCheck = $this->shopModel->checkTask($uid, $emotionDetail);
        if (!$downloadCheck) {
            if (AC::$errorNo) {
                UK::varDump(AC::$errorNo, __METHOD__);
            }
            return FALSE;
        }
        
        // 过期时间处理(包括续约之后的过期时间)
        $contractDateline = $this->shopModel->handleContractDateline($emotionUser['time'], $emotionUser['dateline'], $emotionDetail['period']);
        $dateline = $contractDateline['dateline'];
        $contract = $contractDateline['contract'];
	
        // 购买
        $result = $this->userPayFor($uid, $goodsType, $id, $emotionDetail['price_final'], $dateline, $contract);
        return $result;
    }
    
    //==========================================信纸(改，参照表情)===================================================
    /**
     * 信纸商店
     * @param unknown $param
     * @return boolean|StdClass|number
     */
    private function getLetterPaperList($param){
        $uid      =    intval($param['uid']);
        $type     =    strval($param['type']);
        $goodsType=    $this->shopGoodsType['paper'];
        $redisKey =    $this->shopGoodsRedisKey['paper'];

		if (intval($uid) < 1 && DOP::request('do')!='guest'){
			AC::$errorNo = 'DCP001';
			return FALSE;
		}
    
        // 分页参数
        list($id, $start, $length) = UK::assemblePageData($param);
        
        // 类型
        $type = 'new';
        isset($param['type']) && $type = strval($param['type']);
        if ($type === 'all') $type = 'new';
        
        // 请求数据库
        $letterPapers = $this->shopModel->getShopIdList($redisKey, $goodsType, $type, $id, $start, $length);
        if (empty($letterPapers)){
            return (Object) array();
        }
    
        // 组装返回结构
        $result['papers']  = $this->handleShopListData($letterPapers, $uid, $goodsType, $redisKey);
        $result['banner'] = $this->shopModel->getPaperBannerData();
        $result['banner'] = (Object) array();
        $result['counts'] = count($result['papers']);
    
        return $result;
    }
    
    /**
     * 获取我下载的信纸列表
     * @param unknown $param
     * @return boolean|StdClass|number
     */
    private function getMyLetterPaperList($param){
        $uid     =    intval($param['uid']);
        $goodsType=    $this->shopGoodsType['paper'];
        $redisKey =    $this->shopGoodsRedisKey['paper'];
        
        if ($uid < 1){
            AC::$errorNo = 'DCP001';
            return false;
        }
    
        // 分页参数
        list($id, $start, $length) = UK::assemblePageData($param);
    
        // 请求数据库
        $letterPapers = $this->shopModel->getShopListMeBuyByGoodsType($uid, $goodsType, $start, $length, $id);
        if (empty($letterPapers)){
            return (Object) array();
        }
    
        // 组装返回结构
        $result['papers']  = $this->handleShopListDataMeBuyByGoodsType($letterPapers, $uid, $goodsType, $redisKey);
        $result['counts'] = count($result['papers']);
    
        return $result;
    }
    
    /**
     * 信纸详情
     * @param unknown $param
     * @return boolean|StdClass|unknown
     */
    private function getLetterPaperDetail($param) {
        $uid      =    intval($param['uid']);
        $id       =    intval($param['id']);
        $goodsType=    $this->shopGoodsType['paper'];
        $redisKey =    $this->shopGoodsRedisKey['paper'];
        
        // check params
        if ($id < 1 || $uid < 1 ){
            AC::$errorNo    =   'DCP001';
            return  FALSE;
        }
         
        // 获取信纸详情
        $paperDetail = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
        if (empty($paperDetail)){
            return (Object) array();
        }
        
        // 组装返回数据
        $result = $this->shopModel->assembledShopDetailDataByGoodsType($uid, $paperDetail, $goodsType);
        return $result;
    }
    
    /**
     * 购买信纸
     * @param unknown $param
     * @return boolean
     */
    private function buyLetterPaper($param){
        $uid      =    intval($param['uid']);
        $id       =    intval($param['id']);
        $goodsType=    $this->shopGoodsType['paper'];
        $redisKey =    $this->shopGoodsRedisKey['paper'];
    
        if (empty($uid) || empty($id)){
            AC::$errorNo = 'DCP001';
            return  FALSE;
        }
    
        // 获取详情
        $letterPaper = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
        if (empty($letterPaper)){
            AC::$errorNo = 'DCP002';
            return false;
        }
        
        // 已过期报错
        if ($letterPaper['expire_time'] > 0 && $letterPaper['expire_time'] < AC::SERVER_TIME) {
            AC::$errorNo = 'DCP005';
            return false;
        }
        
        // 是否购买过
        $paperUser = $this->shopModel->getShopUserDetailByGoodsType($uid, $id, $goodsType);
        if ($paperUser && ($paperUser['dateline'] >= AC::SERVER_TIME || $paperUser['dateline'] == 0)){
            return TRUE;
        }
        
        // 判断是否符合下载条件
        $downloadCheck = $this->shopModel->checkTask($uid, $letterPaper);
        if (!$downloadCheck) {
            if (AC::$errorNo) {
                UK::varDump(AC::$errorNo, __METHOD__);
            }
            return FALSE;
        }
        
        // 过期时间处理(包括续约之后的过期时间)
        $contractDateline = $this->shopModel->handleContractDateline($paperUser['time'], $paperUser['dateline'], $letterPaper['period']);
        $dateline = $contractDateline['dateline'];
        $contract = $contractDateline['contract'];
        
        // 购买
        $result = $this->userPayFor($uid, $goodsType, $id, $letterPaper['price_final'], $dateline, $contract);
        return $result;
    }
    
    // =========================================字体商店============================================
    /**
     * 字体商店
     * @param unknown $param
     * @return boolean|StdClass|number
     */
    private function getFontList ($param) {
        $uid      =    intval($param['uid']);
        $type     =    strval($param['type']);
        $goodsType=    $this->shopGoodsType['font'];

		if (intval($uid) < 1 && DOP::request('do')!='guest'){
			AC::$errorNo = 'DCP001';
			return FALSE;
		}
        
        // 分页参数
        list($id, $start, $length) = UK::assemblePageData($param);
        
        // 请求数据库
        $fonts = $this->shopModel->getShopListByGoodsType($goodsType , $start, $length, $id);
        if (empty($fonts)){
            return (Object) array();
        }
        
        // 组装返回结构
        $result['fonts']  = $this->handleShopListDataByGoodsType($fonts, $uid, $goodsType);
        //$result['banner'] = $this->shopModel->getFontBannerData();
        $result['banner'] = (Object) array();
        $result['counts'] = count($result['fonts']);
        
        return $result;
    }
    
    /**
     * 我下载的字体列表
     * @param unknown $param
     * @return boolean|StdClass|number
     */
    private function getMyFontList($param){
        $uid      =    intval($param['uid']);
        $goodsType=    $this->shopGoodsType['font'];
        $redisKey =    $this->shopGoodsRedisKey['font'];
        
        if ($uid < 1){
            AC::$errorNo = 'DCP001';
            return false;
        }
    
        // 分页参数
        list($id, $start, $length) = UK::assemblePageData($param);
    
        // 请求数据库
        $fonts = $this->shopModel->getShopListMeBuyByGoodsType($uid, $goodsType, $start, $length, $id);
        if (empty($fonts)){
            return (Object) array();
        }
    
        // 组装返回结构
        $result['fonts']  = $this->handleShopListDataMeBuyByGoodsType($fonts, $uid, $goodsType, $redisKey);
        $result['counts'] = count($result['fonts']);
    
        return $result;
    }
    
    /**
     * 字体详情
     * @param unknown $param
     * @return boolean|StdClass|unknown
     */
    private function getFontDetail($param){
        $uid      =    intval($param['uid']);
        $id       =    intval($param['id']);
        $goodsType=    $this->shopGoodsType['font'];
        $redisKey =    $this->shopGoodsRedisKey['font'];
    
        // check params
        if ($id < 1 || $uid < 1 &&  DOP::request('do')!='guest' ){
            AC::$errorNo    =   'DCP001';
            return  FALSE;
        }
         
        // 获取字体详情
        $fontDetail = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
        if (empty($fontDetail)){
            return (Object) array();
        }
    
        // 组装返回数据
        $result = $this->shopModel->assembledShopDetailDataByGoodsType($uid, $fontDetail, $goodsType);
        return $result;
    }
    
    /**
     * 购买字体
     * @param unknown $param
     * @return boolean
     */
    private function buyFont($param){
        $uid      =    intval($param['uid']);
        $id       =    intval($param['id']);
        $goodsType=    $this->shopGoodsType['font'];
        $redisKey =    $this->shopGoodsRedisKey['font'];
    
     	if ( (empty($uid) || empty($id)) && DOP::request('do') != 'guest' ){
            AC::$errorNo = 'DCP001';
            return  FALSE;
    	}
        
        // 获取详情
        $fontDetail = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
        if (empty($fontDetail)){
            AC::$errorNo = 'DCP002';
            return false;
        }
    	
        //未登录下载
        if(DOP::request('do') == 'guest'){
            $task = json_decode($fontDetail['task'],true);
            if(empty($task['type'])){
                $this->shopModel->increaseSaleAmount($id);
                return true;
            }
            return false;
        }
	
        // 已过期报错
        if ($fontDetail['expire_time'] > 0 && $fontDetail['expire_time'] < AC::SERVER_TIME) {
            AC::$errorNo = 'DCP005';
            return false;
        }
    
        // 是否购买过
        $fontUser = $this->shopModel->getShopUserDetailByGoodsType($uid, $id, $goodsType);
        if ($fontUser && ($fontUser['dateline'] >= AC::SERVER_TIME || $fontUser['dateline'] == 0)){
            return TRUE;
        }

        // 判断是否符合下载条件
        $downloadCheck = $this->shopModel->checkTask($uid, $fontDetail);
        if (!$downloadCheck) {
            if (AC::$errorNo) {
                UK::varDump(AC::$errorNo, __METHOD__);
            }
            return FALSE;
        }
        
        // 过期时间处理(包括续约之后的过期时间)
        $contractDateline = $this->shopModel->handleContractDateline($fontUser['time'], $fontUser['dateline'], $fontDetail['period']);
        $dateline = $contractDateline['dateline'];
        $contract = $contractDateline['contract'];
    
        // 购买
        $result = $this->userPayFor($uid, $goodsType, $id, $fontDetail['price_final'], $dateline, $contract);
        return $result;
    }
    
    // =========================================皮肤商店============================================
    /**
     * 皮肤商店
     * @param unknown $param
     * @return boolean|StdClass|number
     */
    public function getSkinList ($param) {
        $uid      =    $param['uid'] ? intval($param['uid']) : AC::HOST_UID;
        $type     =    strval($param['type']);
        $goodsType=    $this->shopGoodsType['skin'];
        $redisKey =    $this->shopGoodsRedisKey['skin'];
        
        // 获取版本号
        list($platform, $version) = $this->getPlatFormAndProductVersion();

		if (intval($uid) < 1 && DOP::request('do')!='guest'){
			AC::$errorNo = 'DCP001';
			return FALSE;
		}
    
        // 分页参数
        list($id, $start, $length) = UK::assemblePageData($param);
        
        // 请求包列表
        $shopzips = $this->shopModel->getShopZipList($platform, $goodsType, $version);
        $shopzips = $this->shopModel->getPaginationDataOfShopZipList($id, $length, $shopzips);
        if (empty($shopzips)) return (Object) array();
        
        // 皮肤列表
        $skins = array();
        foreach ($shopzips as $value) {
            $skin = $this->shopModel->getGoodsDetailByGoodsType($value['pid'], $goodsType, $redisKey);
            if (empty($skin)) continue;
            if (($type == 'free') && $skin['price_final'] > 0) continue;
            
            $skin['zip_url'] = $value['zip_url'];
            $skins[] = $skin;
        }
        if (empty($skins)) return (Object) array();
    
        // 组装返回结构
        $result = array();
        $result['skins']  = $this->handleShopListDataByGoodsType($skins, $uid, $goodsType);
        //$result['banner'] = $this->shopModel->getSkinBannerData();
        $result['banner'] = (Object) array();
        $result['counts'] = count($result['skins']);
    
        return $result;
    }
    
    /**
     * 我下载的皮肤列表
     * @param unknown $param
     * @return boolean|StdClass|number
     */
    private function getMySkinList($param){

        $uid      =    intval($param['uid']);
        $goodsType=    $this->shopGoodsType['skin'];
        $redisKey =    $this->shopGoodsRedisKey['skin'];
    
        if ($uid < 1){
            AC::$errorNo = 'DCP001';
            return false;
        }

        // 获取版本号
        list($platform, $version) = $this->getPlatFormAndProductVersion();
        
        // 分页参数
        list($id, $start, $length) = UK::assemblePageData($param);

        // 请求数据库
        $skins = $this->shopModel->getShopListMeBuyByGoodsType($uid, $goodsType, $start, $length, $id);
        if (empty($skins)){
            return (Object) array();
        }
        
        $skinsWithZip = array();
        foreach ($skins as $value) {
            $shopZipInfo = $this->shopModel->getShopZipInfo($value['pid'], $platform, $version);
            $valid = $this->shopModel->checkShopZipValid($version, $shopZipInfo);
            if (!$valid) continue;
            
            $value['zip_url'] = $shopZipInfo['zip_url'];
            $skinsWithZip[] = $value;
        }
        if (empty($skinsWithZip)) return (Object) array();
        
        // 组装返回结构
        $result['skins']  = $this->handleShopListDataMeBuyByGoodsType($skinsWithZip, $uid, $goodsType, $redisKey);
        $result['counts'] = count($result['skins']);
    
        return $result;
    }
    
    /**
     * 皮肤详情
     * @param unknown $param
     * @return boolean|StdClass|unknown
     */
    public function getSkinDetail($param){
        $uid      =    $param['uid'] ? intval($param['uid']) : AC::HOST_UID;
        $id       =    intval($param['id']);
        $goodsType=    $this->shopGoodsType['skin'];
        $redisKey =    $this->shopGoodsRedisKey['skin'];
    
        // check params
        if (DOP::request('do') != 'guest' && ($id < 1 || $uid < 1) ){
            AC::$errorNo    =   'DCP001';
            return  FALSE;
        }

        // 获取版本号
        list($platform, $version) = $this->getPlatFormAndProductVersion();
        
        // 获取皮肤详情
        $skinDetail = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
        if (empty($skinDetail)){
            return (Object) array();
        }
        
        // 获取包信息
        $shopZipInfo = $this->shopModel->getShopZipInfo($id, $platform, $version);
        if (empty($shopZipInfo) || empty($shopZipInfo['zip_url'])) {
            return (Object) array();
        }
        
        $skinDetail['zip_url'] = $shopZipInfo['zip_url'];
    
        // 组装返回数据
        $result = $this->shopModel->assembledShopDetailDataByGoodsType($uid, $skinDetail, $goodsType);
        return $result;
    }
    
    /**
     * 购买皮肤
     * @param unknown $param
     * @return boolean
     */
    private function buySkin($param){
        $uid      =    intval($param['uid']);
        $id       =    intval($param['id']);
        $goodsType=    $this->shopGoodsType['skin'];
        $redisKey =    $this->shopGoodsRedisKey['skin'];
    
        if (empty($uid) || empty($id)){
            AC::$errorNo = 'DCP001';
            return  FALSE;
        }
    
        // 获取详情
        $skinDetail = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
        if (empty($skinDetail)){
            AC::$errorNo = 'DCP002';
            return false;
        }
    
        // 已过期报错
        if ($skinDetail['expire_time'] > 0 && $skinDetail['expire_time'] < AC::SERVER_TIME) {
            AC::$errorNo = 'DCP005';
            return false;
        }
    
        // 是否购买过
        $skinUser = $this->shopModel->getShopUserDetailByGoodsType($uid, $id, $goodsType);
        if ($skinUser && ($skinUser['dateline'] >= AC::SERVER_TIME || $skinUser['dateline'] == 0)){
            return TRUE;
        }
    
        // 判断是否符合下载条件
        $downloadCheck = $this->shopModel->checkTask($uid, $skinDetail);
        if (!$downloadCheck) {
            if (AC::$errorNo) {
                UK::varDump(AC::$errorNo, __METHOD__);
            }
            return FALSE;
        }
    
        // 过期时间处理(包括续约之后的过期时间)
        $contractDateline = $this->shopModel->handleContractDateline($skinUser['time'], $skinUser['dateline'], $skinDetail['period']);
        $dateline = $contractDateline['dateline'];
        $contract = $contractDateline['contract'];
    
        // 购买
        $result = $this->userPayFor($uid, $goodsType, $id, $skinDetail['price_final'], $dateline, $contract);
        return $result;
    }

    /**
     * 送礼物(信纸)
     * @param unknown $param
     * @return boolean
     */
    private function buyPaperForSomeOne ($param) {
        $uid     =    intval($param['uid']);
        $sUid    =    intval($param['sUid']);
        $id      =    intval($param['id']);
        $goodsType=    $this->shopGoodsType['paper'];
        $redisKey =    $this->shopGoodsRedisKey['paper'];
    
        return $this->buyGoodsForSomeOneByGoodsType($uid, $sUid, $id, $goodsType, $redisKey);
    }
    
    /**
     * 送礼物(表情)
     * @param unknown $param
     * @return boolean
     */
    private function buyEmotionForSomeOne ($param) {
        $uid     =    intval($param['uid']);
        $sUid    =    intval($param['sUid']);
        $id      =    intval($param['id']);
        $goodsType=    $this->shopGoodsType['emotion'];
        $redisKey =    $this->shopGoodsRedisKey['emotion'];
        
        return $this->buyGoodsForSomeOneByGoodsType($uid, $sUid, $id, $goodsType, $redisKey);
    }
    
    /**
     * 送礼物
     * @param unknown $uid
     * @param unknown $sUid
     * @param unknown $id
     * @param unknown $goodsType
     * @param unknown $redisKey
     * @return boolean
     */
    private function buyGoodsForSomeOneByGoodsType ($uid, $sUid, $id, $goodsType, $redisKey) {
        // check params
        if ((empty($uid) || empty($id) || empty($sUid)) || ($sUid == $uid) ){
            AC::$errorNo = 'DCP001';
            return  FALSE;
        }
        
        // 获取详情
        $goodsDetail = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
        if (empty($goodsDetail)){
            AC::$errorNo = 'DCP002';
            return false;
        }
        
        // 非粉币购买的表情不能由他人代买
        if (intval($goodsDetail['price_final']) < 1) {
            return FALSE;
        }
        
        // 已过期报错
        if ($goodsDetail['expire_time'] > 0 && $goodsDetail['expire_time'] < AC::SERVER_TIME) {
            AC::$errorNo = 'DCP005';
            return false;
        }
        
        // 判断对方是否购买过
        $goodsUser = $this->shopModel->getShopUserDetailByGoodsType($sUid, $id, $goodsType);
        if ($goodsUser && ($goodsUser['dateline'] >= AC::SERVER_TIME || $goodsUser['dateline'] == 0)){
            return TRUE;
        }
        
        // 判断是否符合下载条件
        $downloadCheck = $this->shopModel->checkTask($uid, $goodsDetail);
        if (!$downloadCheck) {
            if (AC::$errorNo) {
                UK::varDump(AC::$errorNo, __METHOD__);
            }
            return FALSE;
        }
        
        // 过期时间处理(包括续约之后的过期时间)
        $contractDateline = $this->shopModel->handleContractDateline($goodsUser['time'], $goodsUser['dateline'], $goodsDetail['period']);
        $dateline = $contractDateline['dateline'];
        $contract = $contractDateline['contract'];
        
        // 购买
        $result = $this->userPayFor($uid, $goodsType, $id, $goodsDetail['price_final'], $dateline, $contract, $sUid);
        return $result;
    }
    
    public function parseEmotion ($param) {
        $content = strval($param['content']);
        $msgType = '';
        $host_uid = AC::HOST_UID;
        isset($param['msgType']) && $msgType = strval($param['msgType']);
        
        $emotionData = $this->shopModel->parseEmotionData($msgType, $content);
        $result = array('content' => $content, 'msgType' => $msgType, 'data' => $emotionData);
        return $result;
    }
    
    //======================================================================
    private function handleShopListData ($goods_id_list, $uid, $goodsType, $redisKey) {
        $result = $tmp = array();
        foreach ($goods_id_list as $id){
            $tmp = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
            if (empty($tmp)){
                continue;
            }
            $tmp = $this->shopModel->assembledShopListDataByGoodsType($uid, $tmp, $goodsType);
            $result[] = $tmp;
        }
    
        return $result;
    }
	
	private function handelPlanerListData($uid, $goodsType, $redisKey){

		$plannerData = $this->shopModel->getPlannerByType($uid,$goodsType, $redisKey);
		$shopUsers = array();
		if(intval($uid) > 0){
			$shopUser = $this->shopModel->getShopUserByGoodsType($uid,$goodsType);
			foreach ($shopUser as $v){
				array_push($shopUsers,$v['pid']);
			}
		}
		if(!$plannerData){
			return (object) array();
		}
		if(!$shopUsers){
			return $plannerData;
		}
		foreach ($plannerData  as &$value){
				if(in_array($value['id'],$shopUsers)){
					$value['own'] = '1';
					$value['dateline'] = "0";
				}
		}
		return $plannerData;
	}
    
    //=================================完整版======================================
    private function getProEmotionList ($param) {
        $param['type'] = 'vip';
        return $this->getEmotionList($param);
    }
    
    private function getProMyEmotionList ($param) {
        return $this->getMyEmotionList($param);
    }
    
    private function getProEmotionDetail ($param) {
        return $this->getEmotionDetail($param);
    }
    
    private function buyProEmotion ($param) {
        $uid     =    intval($param['uid']);
        $id      =    intval($param['id']);
        $goodsType=    $this->shopGoodsType['pro_emotion'];
        $redisKey =    $this->shopGoodsRedisKey['emotion'];
        
        // check params
        if (empty($uid) || empty($id)){
            AC::$errorNo = 'DCP001';
            return  FALSE;
        }
        
        // 获取详情
        $emotionDetail = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
        if (empty($emotionDetail)){
            AC::$errorNo = 'DCP002';
            return false;
        }
        
        // 已过期报错
        if ($emotionDetail['expire_time'] > 0 && $emotionDetail['expire_time'] < AC::SERVER_TIME) {
            AC::$errorNo = 'DCP005';
            return false;
        }
        
        // 是否购买过
        $emotionUser = $this->shopModel->getShopUserDetailByGoodsType($uid, $id, $goodsType);
        if ($emotionUser && ($emotionUser['dateline'] >= AC::SERVER_TIME || $emotionUser['dateline'] == 0)){
            return TRUE;
        }

        // 购买
        $result = $this->userPayForPro($uid, $goodsType, $id);
        return $result;
    }
    
    private function getProPaperList ($param) {
        $param['type'] = 'vip';
        return $this->getLetterPaperList($param);
    }
    
    private function getProPaperDetail ($param) {
        return $this->getLetterPaperDetail($param);
    }
    
    private function getProMyPaperList ($param) {
        return $this->getMyLetterPaperList($param);
    }
    
    private function buyProPaper ($param) {
        $uid      =    intval($param['uid']);
        $id       =    intval($param['id']);
        $goodsType=    $this->shopGoodsType['pro_paper'];
        $redisKey =    $this->shopGoodsRedisKey['paper'];
    
        if (empty($uid) || empty($id)){
            AC::$errorNo = 'DCP001';
            return  FALSE;
        }
    
        // 获取详情
        $letterPaper = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
        if (empty($letterPaper)){
            AC::$errorNo = 'DCP002';
            return false;
        }
        
        // 已过期报错
        if ($letterPaper['expire_time'] > 0 && $letterPaper['expire_time'] < AC::SERVER_TIME) {
            AC::$errorNo = 'DCP005';
            return false;
        }
        
        // 是否购买过
        $paperUser = $this->shopModel->getShopUserDetailByGoodsType($uid, $id, $goodsType);
        if ($paperUser && ($paperUser['dateline'] >= AC::SERVER_TIME || $paperUser['dateline'] == 0)){
            return TRUE;
        }
        
        // 购买
        $result = $this->userPayFor($uid, $goodsType, $id);
        return $result;
    }
    
    public function getProSkinList ($param) {
        $param['type'] = 'vip';
        return $this->getSkinList($param);
    }
    
    public function getProSkinDetail ($param) {
        return $this->getSkinDetail($param);
    }
    
    private function getProMySkinList ($param) {
        return $this->getMySkinList($param);
    }
    
    private function buyProSkin ($param) {
        $uid     =    intval($param['uid']);
        $id      =    intval($param['id']);
        $goodsType=    $this->shopGoodsType['pro_skin'];
        $redisKey =    $this->shopGoodsRedisKey['skin'];
        
        // check params
        if (empty($uid) || empty($id)){
            AC::$errorNo = 'DCP001';
            return  FALSE;
        }
        
        // 获取详情
        $skinDetail = $this->shopModel->getGoodsDetailByGoodsType($id, $goodsType, $redisKey);
        if (empty($skinDetail)){
            AC::$errorNo = 'DCP002';
            return false;
        }
        
        // 已过期报错
        if ($skinDetail['expire_time'] > 0 && $skinDetail['expire_time'] < AC::SERVER_TIME) {
            AC::$errorNo = 'DCP005';
            return false;
        }
        
        // 是否购买过
        $skinUser = $this->shopModel->getShopUserDetailByGoodsType($uid, $id, $goodsType);
        if ($skinUser && ($skinUser['dateline'] >= AC::SERVER_TIME || $skinUser['dateline'] == 0)){
            return TRUE;
        }

        // 购买
        $result = $this->userPayForPro($uid, $goodsType, $id);
        return $result;
    }
    
    /**
     * 购买
     * @param unknown $uid
     * @param unknown $type
     * @param unknown $id
     * @param number $price
     * @return boolean
     */
    private function userPayFor($uid, $goodsType, $id, $price = 0, $dateline, $contract = FALSE, $sUid = 0){
        // 非本人不能操作
        if ($uid != AC::HOST_UID){
            AC::$errorNo    =   'DCP003';
            return  FALSE;
        }
        
        // 替他人购买
        if ($sUid > 0 && $sUid != $uid) {
            $uid = $sUid;
        }
        
        $result = FALSE;
        if ($contract) {
            // 续约
            $result = $this->shopModel->setShopUserData($uid, $id, $dateline);
        }else {
            // 购买
            $result = $this->shopModel->userbuyShopByGoodsType($uid, $id, $goodsType);
        }
        
        // 扣金币
        if ($result && $price > 0) {
            $isPaid = $this->shopModel->checkShopGoodsIsPaid($uid, $id, $goodsType);
            // 购买
            if (!$isPaid) {
                $this->shopModel->payForShopByGoodsType($uid, $price, $id, $goodsType);
            }
            
            // 续费
            if ($isPaid && $contract){
                $this->shopModel->payForShopByGoodsType($uid, $price, $id, $goodsType, TRUE);
            }
        }
        
    	return $result;
    }
    
    /**
     * 完整版购买
     * @param unknown $uid
     * @param unknown $goodsType
     * @param unknown $id
     * @param number $dateline
     * @return boolean
     */
    private function userPayForPro ($uid, $goodsType, $id, $dateline = 0) {
        // 非本人不能操作
        if ($uid != AC::HOST_UID){
            AC::$errorNo    =   'DCP003';
            return  FALSE;
        }
        
        $result = FALSE;
		$contract = '';
        if ($contract) {
            // 续约
            $result = $this->shopModel->setShopUserData($uid, $id, $dateline);
        }else {
            // 购买
            $result = $this->shopModel->userbuyShopByGoodsType($uid, $id, $goodsType);
        }

        return $result;
    }
    
    /**
     * 处理并返回商店列表数据
     * @param unknown $list
     * @param unknown $uid
     * @param unknown $goodsType
     * @return Ambigous <multitype:, Ambigous, string, multitype:string multitype:string  StdClass multitype:multitype:string   Ambigous <multitype:string, multitype:string > Ambigous <multitype:multitype:string, multitype:multitype:string Ambigous <string>  > >
     */
    private function handleShopListDataByGoodsType ($list, $uid, $goodsType) {
        $result = $tmp = array();
        foreach ($list as $value){
            $tmp = $this->shopModel->assembledShopListDataByGoodsType($uid, $value, $goodsType);
            if (empty($tmp) || ($tmp['expire_time'] < AC::SERVER_TIME && $tmp['expire_time'] > 0)){
                continue;
            }
            $result[] = $tmp;
        }
        
        return $result;
    }
    
    /**
     * 处理并返回我购买的商品列表
     * @param unknown $list
     * @param unknown $uid
     * @param unknown $goodsType
     * @param unknown $redisKey
     * @return Ambigous <multitype:, Ambigous, string, multitype:string multitype:string  StdClass multitype:multitype:string   Ambigous <multitype:string, multitype:string > Ambigous <multitype:multitype:string, multitype:multitype:string Ambigous <string>  > >
     */
    private function handleShopListDataMeBuyByGoodsType ($list, $uid, $goodsType, $redisKey) {
        $result = $tmp = array();
        foreach ($list as $value){
            $tmp = $this->shopModel->getGoodsDetailByGoodsType($value['pid'], $goodsType, $redisKey);
            if (empty($tmp)){
                continue;
            }
            
            // 针对皮肤版本的zip
            if (isset($value['zip_url']) && $value['zip_url']) {
                $tmp['zip_url'] = $value['zip_url'];
            }

            $tmp = $this->shopModel->assembledShopListDataByGoodsType($uid, $tmp, $goodsType);
            $result[] = $tmp;
        }
        
        return $result;
    }
    
    private function getPlatFormAndProductVersion() {
        // 获取版本号
        $product        =    AC::$appInfoList[0];
        $product_version=    AC::$appInfoList[1];
        $os             =    AC::$appInfoList[2];
        $deviceVersion  =    strtolower($product.$os);
        return array($deviceVersion, $product_version);
    }

	private function checkNewAction($action)
	{
		$res = false;
		foreach($this->newActions as $actions){
			if(in_array($action,array_keys($actions))){
				$res = true;
				break;
			}
		}
		return $res;
	}

    private function checkAction($action)
    {
		if($this->checkNewAction($action)){
			$action = 'getInterfaceInfo';
		}
        if (in_array($action, $this->actions) && method_exists($this, $action))  return  TRUE;
        AC::$errorNo    =   'SA004';
        return  ' Error : call do is not exists in ShopController! ';
    }

    public function getShopBanner($param){
        $type = isset($param['type']) ? trim($param['type']) : '';
        if (empty($type)){
            AC::$errorNo = 'DCC001';//参数为空或非法
            return false;
        }
        $list = $this->shopModel->bannerListByType($type);
        empty($list) && $list = [];
        $list = $this->handleShopBannerList($list);
        return $list;
    }

    private function handleShopBannerList($list=[]){
        $ret = [];
        foreach ($list as $item){
            $ret[] = [
                'id' => $item['id'],
                'title' => $item['title'],
                'content' => $item['content'],
                'image' => $item['image_url'],
                'link' => $item['link_url'],
                'action' => $item['action_url'],
                'sort' => $item['sort']
            ];
        }
        return $ret;
    }

}